package com.example.biyesheji.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Controller
@RequestMapping("/api")
public class FileUpLaodController {
    @CrossOrigin
    @ResponseBody
    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public String fileUpload(@RequestParam MultipartFile file) throws IOException {
        if(file.isEmpty()){
            return "上传失败!";
        }
        else {
            byte[] bytes = file.getBytes();
            Path path = Paths.get("C:\\Users\\fireapproval\\Desktop\\data\\"+file.getOriginalFilename());
            Files.write(path,bytes);
//            FileWriter fileWriter = new FileWriter(new File("C:\\Users\\fireapproval\\Desktop\\毕业设计\\数据集\\"+file.getOriginalFilename()));
//            fileWriter.close();

            //flag = true;
        }
        return "C:\\Users\\fireapproval\\Desktop\\data";          //C:\Users\fireapproval\Desktop\毕业设计\数据集
    }
}
